package cn.edu.hubu.hubusmartzoohouse.service.impl;


import cn.edu.hubu.hubusmartzoohouse.entity.Stadium;
import cn.edu.hubu.hubusmartzoohouse.mapper.StadiumMapper;
import cn.edu.hubu.hubusmartzoohouse.service.StadiumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.edu.hubu.hubusmartzoohouse.vo.ResultVo;

import java.util.List;

@Service
public class StadiumImpl implements StadiumService {
    @Autowired
    private StadiumMapper stadiumMapper;

    @Override
    public ResultVo insert(Stadium stadium) {
        int i = stadiumMapper.insert(stadium);
        if (i>0){
            return new ResultVo(200,"添加场馆成功",null);
        } else {
            return new ResultVo(500,"操作有误",null);
        }
    }


    @Override
    public ResultVo delete(int stadiumId){
        return null;
    }




    @Override
    public ResultVo listByUserId(int userId) {
        List<Stadium> list = stadiumMapper.listByUserId(userId);
        //将查询到的result封装到Vo
        ResultVo vo = new ResultVo(200, "查询成功", list);
        return vo;
    }

    @Override
    public ResultVo logicDelete(int stadiumId) {
        int i = stadiumMapper.updateIsDelete(stadiumId, 1);
        return i>0? new ResultVo(200, "删除成功！", null) :
                new ResultVo(500, "删除失败!", null);

    }


//    @Override
//    public ResultVo get(int stadiumId) {
//        Stadium stadium = stadiumMapper.selectByName("111");
//        return new ResultVo(200, "查询成功", stadium);
//    }

    public ResultVo get(int stadiumId){
        Stadium stadium = stadiumMapper.selectById(stadiumId);
        return new ResultVo(200, "查询成功！", stadium);
    }

    @Override
    public ResultVo modifyStadium(Stadium stadium) {
        int i = stadiumMapper.updateStadium(stadium);

        if (i>0){
            return new ResultVo(200, "修改成功！", stadium);
        } else {
            return new ResultVo(500, "修改失败！", stadium);
        }
    }

    @Override
    public ResultVo searchStadiumById(int stadiumId) {
        Stadium stadium = stadiumMapper.selectById(stadiumId);
        if (stadium != null) {
            return new ResultVo(200, "查询成功！", stadium);
        } else {
            return new ResultVo(500, "查询失败: 未找到场馆信息", null);
        }
    }

    @Override
    public ResultVo searchStadiumByName(String stadiumName) {
        Stadium stadium = stadiumMapper.selectByName(stadiumName);
        if (stadium != null) {
            return new ResultVo(200, "查询成功！", stadium);
        } else {
            return new ResultVo(500, "查询失败: 未找到场馆信息", null);
        }
    }

}
